package com.zijin.controller.user;


import com.zijin.PageQureyDTO;
import com.zijin.annotation.Authority;
import com.zijin.dto.user.RoleDTO;
import com.zijin.entity.user.Role;
import com.zijin.result.PageResult;
import com.zijin.result.Result;
import com.zijin.service.user.IRoleService;
import com.zijin.vo.user.RoleVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 角色信息表 前端控制器
 * </p>
 *
 * @author JWei Xu
 * @since 2025-02-01
 */
@Slf4j
@RestController
@RequestMapping("/base/role")
@Api(tags = "角色信息表")
public class RoleController {

    @Resource
    @Lazy
    private IRoleService roleService;

    /** 增 */
    @PostMapping("/addOne")
    @ApiOperation("新增一个角色")
    @Authority("admin")
    public Result<Boolean> addOne(@RequestBody RoleDTO dto){
        return Result.success(roleService.addOne(dto));
    }


    /** 删 */
    @DeleteMapping("/delOne/{id}")
    @ApiOperation("新增一个角色")
    @Authority("admin")
    public Result<Boolean> delOne(@PathVariable Long id){
        return Result.success(roleService.delOne(id));
    }

    /** 改 */
    @PutMapping("/editOne/{id}")
    @ApiOperation("修改一个角色")
    @Authority("admin")
    public Result<Boolean> editOne(@PathVariable Long id,@RequestBody RoleDTO dto){
        return Result.success(roleService.editOne(id,dto));
    }


    /** 查  */
    @GetMapping("/getOne/{id}")
    @ApiOperation("查询一个角色")
    @Authority("admin")
    public Result<Role> getOne(@PathVariable Long id, @RequestBody RoleDTO dto){
        return Result.success(roleService.getRole(id));
    }

    @GetMapping("/getPage")
    @ApiOperation("查询分页角色")
    @Authority("admin")
    public Result<PageResult> getPage(PageQureyDTO dto){
        log.info(dto.toString());
        return Result.success(roleService.getPage(dto));
    }

    @GetMapping("/getList")
    @ApiOperation("查询分页角色")
    @Authority("admin")
    public Result<List<RoleVo>> getList(PageQureyDTO dto){
        log.info(dto.toString());
        return Result.success(roleService.getList(dto));
    }





}
